package com.jrx.anytxn.transaction.service;


import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.param.entity.TlFilePaymentLog;
import com.jrx.anytxn.transaction.bean.FilePaymentSaveBean;
import com.jrx.anytxn.transaction.bean.PaymentSaveBean;
import com.jrx.anytxn.transaction.dto.payment.ThirdPartyPaymentRep;
import com.jrx.anytxn.transaction.dto.payment.ThirdPartyPaymentRes;
import com.jrx.anytxn.transaction.entity.AmLoanAccountInfo;
import com.jrx.anytxn.transaction.entity.AmLoanMainInfo;
import com.jrx.anytxn.transaction.entity.TlThirdPartyPayment;

import java.util.Date;

/**
 * 第三方还款处理接口
 */
public interface IThirdPartyPaymentService {

    /**
     * 第三方还款
     * @param thirdPartyPaymentRep
     * @param bussinessDate
     * @return
     */
    TlThirdPartyPayment thirdPartyPay(ThirdPartyPaymentRep thirdPartyPaymentRep, Date bussinessDate, AmLoanMainInfo loanMainInfo, AmLoanAccountInfo loanAccountInfo) throws TxnBizException;

    /**
     * 第三方还款分配
     *
     * @param tlThirdPartyPayment 三方还款流水信息
     */
    void thirdPartyAllocation(TlThirdPartyPayment tlThirdPartyPayment) throws TxnBizException;


    /**
     * 分配
     * @param tlThirdPartyPayment
     * @param bussinessDate
     * @throws TxnException
     */
    void dealAllocationByThirdParty(TlThirdPartyPayment tlThirdPartyPayment, Date bussinessDate) throws Exception;

    /**
     * 通过文件还款流水生成三方还款流水
     * @param paymentLog
     * @param loan
     * @param bussinessDate
     * @return
     */
    TlThirdPartyPayment generateThirdLog(TlFilePaymentLog paymentLog, AmLoanAccountInfo loan, Date bussinessDate) throws TxnBizException;

    /**
     * 文件三方还款分配
     * @param filePaymentSaveBean
     * @param tlThirdPartyPayment
     * @throws TxnBizException
     */
    boolean fileThirdPartyAllocation(FilePaymentSaveBean filePaymentSaveBean, TlThirdPartyPayment tlThirdPartyPayment) throws TxnBizException;

    /**
     * 文件三方还款分配
     * @param tlThirdPartyPayment
     * @param bussinessDate
     * @return
     * @throws Exception
     */
    PaymentSaveBean dealAllocationByFileThirdParty(TlThirdPartyPayment tlThirdPartyPayment, Date bussinessDate) throws Exception;

    /**
     * 处理并保存文件还款分配信息
     * @param tlThirdPartyPayment
     * @param bussinessDate
     * @throws Exception
     */
    void dealAndSaveFilePayAllocate(TlThirdPartyPayment tlThirdPartyPayment, Date bussinessDate) throws Exception;

    /**
     * 查询第三方还款
     *
     * @param channel 渠道
     * @param customerId 客户ID
     * @param tenantId 租户ID
     * @param pageNum 页码
     * @param pageSize 页大小
     * @param seqNo 流水号
     * @param beginDate 发起开始时间
     * @param endDate 发起结束时间
     * @return ThirdPartyPaymentRes
     */
    TxnPage<ThirdPartyPaymentRes> getThirdPartyPaymentWithPage(String channel, String customerId, String tenantId, Integer pageNum, Integer pageSize, String seqNo, String beginDate, String endDate);

    /**
     * 查询第三方还款流水表信息
     *
     * @param tenantId 租户ID
     * @param seqNo 流水号
     * @param customerId 客户ID
     * @return ThirdPartyPaymentRes
     */
    ThirdPartyPaymentRes getThirdPartyPaymentBySeqNoAndCusId(String tenantId, String seqNo, String customerId);
}
